/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package javaapplication1;

import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.widgets.Canvas;

/**
 *
 * @author Oren
 */

// the Box class
public class Box {
    private Position boxpos;
    private String boxname;
    private boolean visable;

    
    public Box(String name)
    {
        boxpos = new Position(0,0);
        boxname = name;
        visable = true;
    }

    public Position getPosition()
    {
        return boxpos ;
    }

    public void setNonVisable()
    {
        visable = false;
    }
    public void setVisable()
    {
        visable = true;
    }
    public boolean getVisable()
    {
        return visable;
    }

    public void setPosition(Position position) {
        boxpos = position;
        visable = true;

    }
    public String getName() {return boxname;}
    public void paint(PaintEvent e){
	if (visable)
        {
            Canvas c=(Canvas)e.widget;	// get the canvas
            int maxX = c.getSize().x;	// max size
            int maxY = c.getSize().y;
            int mx=maxX/2,my=maxY/2;	// mid point as (0,0)
            int myX= mx + boxpos.x;	// set the current position
            int myY= my - boxpos.y;	// set the current position

            e.gc.drawLine(myX-7, myY+7 ,myX+7, myY+7);
            // drawing the right line :
            e.gc.drawLine(myX+7, myY+7,myX+7, myY-7);
            // drawing the left line :
            e.gc.drawLine(myX-7, myY+7, myX-7, myY-7);
            // draw the upper line
            e.gc.drawLine(myX-7, myY-7,myX+7, myY-7 );
            // add the "B"
            e.gc.drawString("B", myX-2, myY-6);
        }
}
}
